<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>$watch和一个坑</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo">
      <h1>我叫{{person.name}}，今年{{person.age}}岁了</h1>
      <button @click="person.name = '李四' ">点我修改名字</button>
      <button @click="person.age = 50 ">点我修改年龄</button>
      <button @click="person = {name:'tony',age:99} ">点我修改整个person</button>
    </div>

    <script type="text/javascript">
      let vm = new Vue({
        el:'#demo',
        data:{
          person:{name:'晶晶',age:18}
        },
      })

      setTimeout(() => {
        vm.$watch('person',{
          deep:true,
          handler(value){
            console.log('person变化了',value)
          }
        })

        // vm.$watch('person',function(value){
        //   console.log('person变化了',value)
        // })
      }, 2000);
    </script>
  </body>
</html>